﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace EntityDA
{
    public class TacGiaDB
    {
        public TacGiaData GetOneTacGia(int MaTG)
        {
            ConnectionDB cn = new ConnectionDB();
            string sql = "";
            if (MaTG == -1)
                return null;
            else
            {
                sql = "select * from TacGia where MaTG=@MaTG";
                cn.cmd.Parameters.Add(new SqlParameter("@MaTG", MaTG));

            }
            cn.cmd.CommandText = sql;
            SqlDataReader reader = cn.cmd.ExecuteReader();
            TacGiaData TacGia = null;
            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    TacGia = new TacGiaData();
                    if (!reader.IsDBNull(0))
                        TacGia.MaTG = reader.GetInt32(0);
                    if (!reader.IsDBNull(1))
                        TacGia.TenTG = reader.GetString(1);
                    if (!reader.IsDBNull(2))
                        TacGia.DiaChi = reader.GetString(2);
                    if (!reader.IsDBNull(3))
                        TacGia.DT = reader.GetString(3);
                }
            }

            return TacGia;
        }

        public List<TacGiaData> GetAllTacGia()
        {
            List<TacGiaData> DSTacGia = new List<TacGiaData>();
            ConnectionDB cn = new ConnectionDB();
            string sql = "";
                sql = "select * from TacGia";
            return DSTacGia;
        }

    }
}